﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        //注册
        private void button1_Click(object sender, EventArgs e)
        {
            string conString = "server =.;database =Blogs;uid = sa; pwd =123456";

            var sqlCon = new SqlConnection(conString);

            sqlCon.Open();


            var insertString = string.Format("insert into Users(username,password)values('" + textBox1.Text + "','" + textBox2.Text + "')", sqlCon);

            SqlCommand cmd = new SqlCommand(insertString, sqlCon);

            var res = cmd.ExecuteNonQuery();

            if (res == 1)
            {
                MessageBox.Show("注册成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("注册失败");
                this.Close();
            }
        }


        //取消
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
